/**
 * jims
 */
package com.jims.master.modules.sys.web;

import com.jims.master.common.data.StringData;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.common.web.BaseController;
import com.jims.master.modules.sys.entity.TComobVsClinic;
import com.jims.master.modules.sys.service.TComobVsClinicService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Controller
 * @author 系统管理员
 * @version 2017-06-12
 */
@Controller
@RequestMapping(value = "${adminPath}/tComobVsClinic/tComobVsClinic")
public class TComobVsClinicController extends BaseController {

	@Autowired
	private TComobVsClinicService tComobVsClinicService;
	
	@ModelAttribute
	public TComobVsClinic get(@RequestParam(required=false) String id) {
		TComobVsClinic entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tComobVsClinicService.get(id);
		}
		if (entity == null){
			entity = new TComobVsClinic();
		}
		return entity;
	}
	
	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String list(TComobVsClinic tComobVsClinic, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TComobVsClinic> page = tComobVsClinicService.findPage(new Page<TComobVsClinic>(request, response), tComobVsClinic); 
		model.addAttribute("page", page);
		return "modules/titemcomobo/tComobVsClinicIndex";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "form")
	public String form(TComobVsClinic tComobVsClinic, String clinicName,Model model) {
		List<TComobVsClinic> list = tComobVsClinicService.findList(tComobVsClinic);
		model.addAttribute("tComobVsClinic", tComobVsClinic);
		model.addAttribute("list", list);
		model.addAttribute("clinicName", clinicName);
		return "modules/titemcomobo/tComobVsClinicForm";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "save")
	@ResponseBody
	public StringData save(TComobVsClinic tComobVsClinic, Model model) {
	    StringData data=new StringData();
		int i=tComobVsClinicService.save(tComobVsClinic);
        if(i>0){
            data.setCode("success");
            data.setData("保存成功");
        }else{
            data.setCode("error");
            data.setData("保存失败");
        }
        return data;
	}
	@RequiresPermissions("user")
	@RequestMapping(value = "delete")
	@ResponseBody
	public StringData delete(TComobVsClinic tComobVsClinic) {
	    StringData data=new StringData();
		int i=tComobVsClinicService.delete(tComobVsClinic);
        if(i>0){
            data.setCode("success");
            data.setData("删除成功");
        }else{
            data.setCode("error");
            data.setData("删除失败");
        }
		return data;
	}

}